/**
 * cookie工具类
 * @author zijing.zhang
 */
(function($ns){
    
    $ns.domain = function() {
        var url = location.href,
            regex = /^http:\/\/(.+?)[\/:]/;
        var _domain =  url.match(regex) != null ? url.match(regex)[1] : "localhost";
        Qadmin.FW.Log.debug("获取到domain: "+ _domain);
        return _domain;
    };
    
    $ns.path = "/";
    
    /**
     * @param sName
     */
    $ns.get = function(sName){
        var aCookie = document.cookie.split("; ");
        for (var i=0; i < aCookie.length; i++)
        {
            var aCrumb = aCookie[i].split("=");
            if (sName == aCrumb[0])
                return unescape(aCrumb[1]);
        }
        return null;
    };
    
    /**
     * @param sName 
     * @param sValue
     * @param cyctime
     */
    $ns.set = function(sName, sValue, cyctime){
        var date =  new Date(); 
        date.setTime(date.getTime()+  cyctime); 
        document.cookie = sName + "=" + escape(sValue) + "; expires=" + date.toGMTString() + ";domain=" + this.domain() + ";path=" + this.path;
    };
    
    /**
     * @param sName
     */
    $ns.remove = function(sName) {
        document.cookie = sName + "=" + this.getCookie(sName) + "; expires="+ new Date().toGMTString() + ";domain=" + this.domain() + ";path=" + this.path;
    };
})(using("Qadmin.FW.Cookie"));